﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _02_Process_进程通讯_1
{

    /// <summary>
    /// 进程通讯的结构体
    /// </summary>
    public struct COPYDATASTRUCT
    {
        public IntPtr dwData;//这个值是可以为任意数值，通常这个可以作为标志位存在
        public int cbData;//指定lpData指向的缓冲区的字节数
        [MarshalAs(UnmanagedType.LPStr)]//规定发送的数据类型为String字符串类型
        public string lpData;//发送的字符串
    }

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == 0x004A)//接受指定的消息
            {
                COPYDATASTRUCT cds = new COPYDATASTRUCT();
                Type mytype = cds.GetType();
                cds = (COPYDATASTRUCT)m.GetLParam(mytype);
                this.label1.Text = cds.lpData;
            }
        }

    }
}
